package com.easyselection.utils;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;
/**
 * @author 90616
 * @description
 * @create 2025/7/4 21:01
 */

public class JwtUtils {

    //设置密钥字符串的编码格式base64
    //// easySelection的base64编码格式 -> "ZWFzeVNlbGVjdGlvbg=="
    private static String signKey = "ZWFzeVNlbGVjdGlvbg==";

    /**
     * 生成JWT令牌
     * @return
     */
    public static String generateJWT(Map<String,Object> claims){
        String jwt = Jwts.builder()
                .addClaims(claims)
                .signWith(SignatureAlgorithm.HS256, signKey)
                .compact();
        return jwt;

    }

    /**
     * 解析JWT令牌
     *
     * @param jwt JWT令牌
     */
    public static Claims parseJWT(String jwt) throws Exception{
        Claims claims = Jwts.parser()
                .setSigningKey(signKey)
                .parseClaimsJws(jwt)
                .getBody();
        return claims;
    }


}
